package com.oneinlet

import org.junit.Test
import java.util.*

/**
 * Created by WangZiHe on 2018/5/11
 * QQ/WeChat:648830605
 * QQ-Group:368512253
 * Blog:www.520code.net
 * Github:https://github.com/yancheng199287
 */
class TestYCDate {


    @Test
    fun testFormatDate() {
        println(YCDate.formatDate(Date(), YCDate.DateFormat.YYYY_MM_DD))
        println(YCDate.formatDate(Date(), YCDate.DateFormat.YYYY_YEAR_MM_MONTH_DD_DAY))
        println(YCDate.formatDate(Date(), YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS))
    }


    @Test
    fun testSetDate() {
        var date = Date()
        date = YCDate.setDate(date, 1992, YCDate.DateUnit.YEAR)
        date = YCDate.setDate(date, 12, YCDate.DateUnit.MONTH)
        date = YCDate.setDate(date, 7, YCDate.DateUnit.DAY)
        date = YCDate.setDate(date, 4, YCDate.DateUnit.HOUR)
        date = YCDate.setDate(date, 30, YCDate.DateUnit.MINUTE)
        date = YCDate.setDate(date, 500, YCDate.DateUnit.MILLISECOND)
        println(YCDate.formatDate(date, YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS_SSS))

    }

    @Test
    fun testAddDate() {
        var date = Date()
        date = YCDate.addDate(date, 1, YCDate.DateUnit.YEAR)
        date = YCDate.addDate(date, 2, YCDate.DateUnit.MONTH)
        date = YCDate.addDate(date, -3, YCDate.DateUnit.DAY)
        date = YCDate.addDate(date, 4, YCDate.DateUnit.HOUR)
        date = YCDate.addDate(date, 5, YCDate.DateUnit.MINUTE)
        date = YCDate.addDate(date, 6, YCDate.DateUnit.MILLISECOND)
        println(YCDate.formatDate(date, YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS_SSS))
        println(YCDate.formatDate(date, "yyyy/MM/dd"))
    }


    @Test
    fun testDiffBetweenDate() {
        val yesterday = YCDate.parserDate("2016-03-01 01:30:00", YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS)
        val today = YCDate.parserDate("2016-03-02 00:10:00", YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS)

        val year = YCDate.diffBetweenDate(yesterday, today, YCDate.DateUnit.YEAR)
        val month = YCDate.diffBetweenDate(yesterday, today, YCDate.DateUnit.MONTH)
        val day = YCDate.diffBetweenDate(yesterday, today, YCDate.DateUnit.DAY)

        val hour = YCDate.diffBetweenDate(yesterday, today, YCDate.DateUnit.HOUR)
        val minute = YCDate.diffBetweenDate(yesterday, today, YCDate.DateUnit.MINUTE)
        val second = YCDate.diffBetweenDate(yesterday, today, YCDate.DateUnit.SECOND)
        val millils = YCDate.diffBetweenDate(yesterday, today, YCDate.DateUnit.MILLISECOND)
        println("today: ${YCDate.formatDate(today, YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS)}  yesterday: ${YCDate.formatDate(yesterday, YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS)}")
        println("$year 年 $month 月 $day 日 $hour 时 $minute 分 $second 秒 $millils 毫秒")
    }

    @Test
    fun dateAtBetween() {
        val plan = YCDate.parserDate("2016-03-01 01:30:59", YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS)
        val yesterday = YCDate.parserDate("2016-03-01 01:30:00", YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS)
        val today = YCDate.parserDate("2016-03-02 00:10:00", YCDate.DateFormat.YYYY_MM_DD_HH_MM_SS)
        println("判断计划时间是否在起止时间内：${YCDate.dateAtBetween(plan, yesterday, today)}")
    }


    @Test
    fun testGetTimeNodeWithDay() {
        val date = Date()
        val startDate = YCDate.getTimeNodeWithDay(date, YCDate.DateNode.START)
        val endDate = YCDate.getTimeNodeWithDay(date, YCDate.DateNode.END)
        println(YCDate.formatDate(startDate))
        println(YCDate.formatDate(endDate))

    }



}
